package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC829 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int consecutiveNumbersSum(int n) {
            int ans = 0;
            n *= 2;
            for (int k = 1; k * k < n; k++) {
                if (n % k != 0) continue;
                if ((n / k - (k - 1)) % 2 == 0) ans++;
            }
            return ans;
        }
    }

    class Solution_Old {
        public int consecutiveNumbersSum(int N) {
            while ((N & 1) == 0) N >>= 1;
            int ans = 1, d = 3;

            while (d * d <= N) {
                int e = 0;
                while (N % d == 0) {
                    N /= d;
                    e++;
                }
                ans *= e + 1;
                d += 2;
            }

            if (N > 1) ans <<= 1;
            return ans;
        }
    }


    public void run() {
        int[] arr = InputUtil.toIntegerArray("[1,2,3]");
        System.out.println(new Solution().toString());
    }

    public static void main(String[] args) throws Exception {
        LC829 an = new LC829();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
